<?php
class SmartyView extends View{
    private $smarty = null;
    public function __construct() {
        if (!defined('SMARTY_DIR')) define('SMARTY_DIR', THIRD_CLASS_DIR . '/Smarty/');
        require_once(SMARTY_DIR . '/Smarty.class.php');
        $this->smarty = new Smarty();
        $this->smarty->left_delimiter = Config::get('TPL_DELI_LEFT');
        $this->smarty->right_delimiter = Config::get('TPL_DELI_RIGHT');
    }
    
    protected function setVars($vars) {
        foreach($vars as $key=>$val) {
            $this->smarty->assign($key, $val);
        }
    }

    protected function parseTpl($template) {
        $tplDir = dirname($template);
        //$fileName = basename($template);
        $this->smarty->template_dir = self::$tplDir ? self::$tplDir: $tplDir;
        $cacheDir = TMP_DIR . '/' . dirname(str_replace(TPL_DIR, '', $template)) . '/';
        if (false == is_dir($cacheDir)) @mkdir($cacheDir, 0777, true);
        $this->smarty->compile_dir = self::$cacheDir ? self::$cacheDir : $cacheDir;
        return $this->smarty->fetch($template);
    }
};
?>